/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package domain.taskManagement.models;

import domain.taskManagement.exceptions.DuplicateTaskException;
import domain.taskManagement.exceptions.TaskNotFoundException;
import java.util.ArrayList;

/**
 *
 * @author peterfrem
 */
public class TaskList {
    private ArrayList<Task> taskList;
    
    public void removeTask(Task task) throws TaskNotFoundException{
	boolean taskFound = false;
	
	for(int i = 0; i <= this.taskList.size(); i++){
	    if(this.taskList.get(i).getId() == task.getId()){
		this.taskList.remove(i);
		taskFound = true;
		break;
	    }
	}
	
	if(taskFound == false){
	    throw new TaskNotFoundException();
	}
    }
    
    public void addTask(Task task) throws DuplicateTaskException{
	
	for(Task t : this.taskList){
	    if(t.getId() == task.getId()){
		throw new DuplicateTaskException();
	    }
	}
	
	this.getTaskList().add(task);
    }

    /**
     * @return the tasks
     */
    public ArrayList<Task> getTaskList() {
	return taskList;
    }

    /**
     * @param tasks the tasks to set
     */
    public void setTaskList(ArrayList<Task> tasks) {
	this.taskList = tasks;
    }
    
}
